﻿using Microsoft.AspNetCore.Mvc.Filters;

namespace MES.Server.API
{
    public class ExceptionFilters:IExceptionFilter
    {
        ILogger<ExceptionFilters> log;

        public ExceptionFilters(ILogger<ExceptionFilters> log)  
        {
            this.log = log;
        }
        public void OnException(ExceptionContext context)  
        {
            log.LogError($"{DateTime.Now}发生全局异常{context.Exception.Message}");  //日志记录全局异常
            context.ExceptionHandled = true;  //修改异常状态
        }
    }
}
